package ph.com.gs3.formalistics.view.document;

import java.util.List;

import ph.com.gs3.formalistics.R;
import ph.com.gs3.formalistics.view.document.abstractfields.TextTypeFieldView;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;

public class DefaultDocumentFields extends ScrollView {

	private LinearLayout llFieldsContainer;

	public DefaultDocumentFields(Context context,
	        DocumentDynamicViewContentsManager documentViewContentsManager) {
		super(context);

		LayoutInflater.from(context).inflate(R.layout.fragment_default_document_fields, this, true);

		llFieldsContainer = (LinearLayout) findViewById(R.id.Document_llFieldsContainer);

		List<View> documentViewContents = documentViewContentsManager.getOrderedViewContents();

		for (View documentViewContent : documentViewContents) {
			llFieldsContainer.addView(documentViewContent);

			// Trigger the onChange event of each view that does not automatically trigger
			// it once added to the view.
			if (documentViewContent instanceof TextTypeFieldView) {
				((TextTypeFieldView) documentViewContent).notifyValueChanged();
			}

		}

	}
}
